package com.cctc.processor.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @Name BeanTracingProcessor
 * @Description: Bean 实例追踪处理器
 * @Author: lichao
 * @Email: li2chao@126.com
 * @Date: 2024-01-15 11:19:09
 **/
public class BeanTracingProcessor implements BeanPostProcessor {

    /**
     * 在 InitializingBean.afterPropertiesSet() 初始化回调前被执行
     * @param bean 目标 Bean 实例
     * @param beanName 目标 Bean 名称
     * @return java.lang.Object
     * @author lichao
     * @email li2chao@126.com
     * @date 2024/01/15 11:21:04
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("在 InitializingBean.afterPropertiesSet() 初始化回调前被执行... ...");
        System.out.println("--> Bean: " + beanName + ", created: " + bean.toString());
        return bean;
    }

    /**
     * 在 InitializingBean.afterPropertiesSet() 初始化回调后被执行
     * @param bean 目标 Bean 实例
     * @param beanName 目标 Bean 名称
     * @return java.lang.Object
     * @author lichao
     * @email li2chao@126.com
     * @date 2024/01/15 11:22:28
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("在 InitializingBean.afterPropertiesSet() 初始化回调后被执行... ...");
        System.out.println("--> Bean: " + beanName + ", created: " + bean.toString());
        return bean;
    }

}

